package controllers

import (
	"dispatch-system/service"

	beego "github.com/beego/beego/v2/server/web"
)

type MainController struct {
	beego.Controller
}

type DispatchSystemController struct {
	beego.Controller
}

func (c *MainController) Get() {
	c.Data["Website"] = "beego.vip"
	c.Data["Email"] = "astaxie@gmail.com"
	c.TplName = "index.tpl"
}

// 下单
func (c *DispatchSystemController) CreateOrder() {
	user := c.GetString("user")
	order := service.CreateOrder(user)

	c.Data["json"] = map[string]interface{}{"code": 200, "message": "下单成功", "data": order}
	c.ServeJSON()
}

// 获取出租车派单排行榜
func (c *DispatchSystemController) GetRankings() {
	rankings := service.GetRankings()

	c.Data["json"] = map[string]interface{}{"code": 200, "message": "获取成功", "data": rankings}
	c.ServeJSON()
}

// 添加出租车
func (c *DispatchSystemController) AddTaxi() {
	driver := c.GetString("driver")
	taxi := service.AddTaxi(driver)
	c.Data["json"] = map[string]interface{}{"code": 200, "message": "添加成功", "data": taxi}
	c.ServeJSON()
}
